home *** CD-ROM | disk | FTP | other *** search
/ HTBasic 9.3 / HTBasic 9.3.iso / 93win / data1.cab / Basic_Plus_Examples / BMAPVIEW < prev    next >
Encoding:
Text File  |  2005-03-02  |  6.7 KB  |  199 lines

  1. 10   ! ******************************************************************
  2. 20    !
  3. 30   ! Example: Bitmap Viewer
  4. 40    !
  5. 50   ! This program demonstrates the use of the BITMAP widget. It
  6. 60   ! allows you to bring in and display bitmaps, as well as select
  7. 70   ! portions of them and save them in a file.
  8. 80    !
  9. 90   ! It also demonstrates the SCROLLABLE attribute for the PANEL ...
  10. 100   ! in particular the various operations needed to make SCROLL WIDTH
  11. 110   ! and SCROLL HEIGHT as correct as possible..
  12. 120   !
  13. 130   ! ******************************************************************
  14. 140   !
  15. 150   ! A few variables:
  16. 160   !
  17. 170   !   S$:        General-purpose string.
  18. 180   !   N:         General-purpose variable.
  19. 190   !   Btn:       Returns button value from dialogs.
  20. 200   !   Sc:        Scroll factor.
  21. 210   !   Bitfile$:  Name of bitmap file to be read.
  22. 220   !   Dirname$:  Directory name returned from FILE dialog.
  23. 230   !   B1$(*):    Stores MENU BUTTONS.
  24. 240   !   A1$,A2$:   Stores dialog attributes.
  25. 241  DIM S$[256]
  26. 280  INTEGER N,Btn,Sc
  27. 290  DIM Bitfile$[100],Dirname$[100],Btns$(1:3)[50],A1$[50],A2$[50]
  28. 300   !
  29. 310  DATA "BMP File","XWD File","Cancel","DIALOG BUTTONS","SELECTION",20
  30. 320  READ Btns$(*),A1$,A2$,Sc
  31. 330   !
  32. 340   ! Widget dimensions.
  33. 350   !
  34. 360  INTEGER Pw,Ph,Px,Py,Iw,Ih,Ww,Wh,Wx,Wy
  35. 370   !
  36. 380   ! Variables for display scaling.
  37. 390   !
  38. 400  INTEGER Cursor,D(1:4),Dw,Dh
  39. 410   !
  40. 420   ! Get display size.
  41. 430   !
  42. 440  GESCAPE CRT,3;D(*)
  43. 450  Dw=D(3)-D(1)
  44. 460  Dh=D(4)-D(2)
  45. 470   !
  46. 480  CLEAR SCREEN
  47. 490  KEY LABELS OFF
  48. 500  RUNLIGHT OFF
  49. 510  STATUS CRT,10;Cursor
  50. 520  CONTROL CRT,10;0
  51. 530   !
  52. 540  Pw=Dw*.7         ! PANEL width.
  53. 550  Ph=Dh*.7         ! PANEL height.
  54. 560  Px=(Dw-Pw)/2     ! Center PANEL.
  55. 570  Py=(Dh-Ph)/2
  56. 580   !
  57. 590   ! Create PANEL for BITMAP widget. Note how the SCROLL WIDTH
  58. 600   ! and HEIGHT are set to a small value so that scroll bars will not
  59. 610   ! appear initially. The actual heights are set later to fit the bitmap
  60. 620   ! that has been loaded.
  61. 630   !
  62. 640  ASSIGN @Main TO WIDGET "PANEL";SET ("VISIBLE":0)
  63. 650  CONTROL @Main;SET ("X":Px,"Y":Py,"WIDTH":Pw,"HEIGHT":Ph)
  64. 660  CONTROL @Main;SET ("TITLE":"Example: Bitmap Viewer")
  65. 670  CONTROL @Main;SET ("SIZE CONTROL":"SCROLLABLE","MINIMIZABLE":1)
  66. 680  CONTROL @Main;SET ("SCROLL WIDTH":1,"SCROLL WIDTH UNITS":Sc)
  67. 690  CONTROL @Main;SET ("SCROLL HEIGHT":1,"SCROLL HEIGHT UNITS":Sc)
  68. 700   !
  69. 710   ! Build menu.
  70. 720   !
  71. 730  ASSIGN @Menu TO WIDGET "PULLDOWN MENU";PARENT @Main
  72. 740  CONTROL @Menu;SET ("LABEL":"Menu")
  73. 750  ASSIGN @Getfile TO WIDGET "MENU BUTTON";PARENT @Menu
  74. 760  CONTROL @Getfile;SET ("LABEL":"Get Bitmap File")
  75. 770  ASSIGN @Savefile TO WIDGET "MENU BUTTON";PARENT @Menu
  76. 780  CONTROL @Savefile;SET ("LABEL":"Cut Bitmap To File")
  77. 790  ASSIGN @Cd TO WIDGET "MENU BUTTON";PARENT @Menu
  78. 800  CONTROL @Cd;SET ("LABEL":"Change Directory")
  79. 810  ASSIGN @S TO WIDGET "MENU SEPARATOR";PARENT @Menu
  80. 820  ASSIGN @Quit TO WIDGET "MENU BUTTON";PARENT @Menu
  81. 830  CONTROL @Quit;SET ("LABEL":"Quit")
  82. 840   !
  83. 850   ! Create and size BITMAP widget. (Setting RETAIN RASTER makes the
  84. 860   ! widget redraw quickly when overwritten by a dialog.)
  85. 870   !
  86. 880  ASSIGN @Bitmap TO WIDGET "BITMAP";PARENT @Main
  87. 890  CONTROL @Bitmap;SET ("RETAIN RASTER":1,"AUTO SIZE":1)
  88. 900  STATUS @Main;RETURN ("INSIDE WIDTH":Iw,"INSIDE HEIGHT":Ih)
  89. 910  Wx=Iw*.01
  90. 920  Wy=Ih*.01
  91. 930  Wh=Ih*.98
  92. 940  Ww=Iw*.98
  93. 950  CONTROL @Bitmap;SET ("X":Wx,"Y":Wy,"WIDTH":Ww,"HEIGHT":Wh)
  94. 960   !
  95. 970   ! Set events.
  96. 980   !
  97. 990  ON EVENT @Getfile,"ACTIVATED" GOSUB Getbitfile
  98. 1000 ON EVENT @Savefile,"ACTIVATED" GOSUB Savebits
  99. 1010 ON EVENT @Cd,"ACTIVATED" GOSUB Chdir
  100. 1020 ON EVENT @Quit,"ACTIVATED" GOTO Finis
  101. 1030  !
  102. 1040 CONTROL @Main;SET ("VISIBLE":1)
  103. 1050  !
  104. 1060  ! Loop and wait for input.
  105. 1070  !
  106. 1080 LOOP
  107. 1090 END LOOP
  108. 1100 STOP
  109. 1110  !
  110. 1120  ! *********************** End of Main Program **********************
  111. 1130  !
  112. 1140  ! This routine gets a bitmap file and displays it.  Note how it gets
  113. 1150  ! the bitmap size and sets up PANEL scrolling accordingly. Note also
  114. 1160  ! how it turns the BITMAP widget invisible so the display will
  115. 1170  ! "thrash" as little as possible.
  116. 1180  !
  117. 1190 Getbitfile: !
  118. 1200 S$="Please enter the name of a bitmap (.BMP) file:"
  119. 1210 DIALOG "FILE",S$,Btn;RETURN ("SELECTION":Bitfile$)
  120. 1220  !
  121. 1230 IF Btn=0 THEN
  122. 1240     CLEAR ERROR
  123. 1250     ON ERROR GOSUB Errtrap
  124. 1260     CONTROL @Bitmap;SET ("VISIBLE":0,"BITMAP FILE":Bitfile$)
  125. 1270     OFF ERROR
  126. 1280     IF ERRN<>0 THEN
  127. 1290         DIALOG "ERROR","Can't open file / invalid bitmap file."
  128. 1300         CONTROL @Bitmap;SET ("BITMAP FILE":"","VISIBLE":1)
  129. 1310     ELSE
  130. 1320         CONTROL @Bitmap;SET ("VISIBLE":0)
  131. 1330         STATUS @Bitmap;RETURN ("BITMAP HEIGHT":Wh,"BITMAP WIDTH":Ww)
  132. 1340         CONTROL @Main;SET ("SCROLL HEIGHT":2+INT(Wh/Sc))
  133. 1350         CONTROL @Main;SET ("SCROLL WIDTH":2+INT(Ww/Sc))
  134. 1360         CONTROL @Bitmap;SET ("VISIBLE":1)
  135. 1370         DIALOG "INFORMATION","File read completed!"
  136. 1380     END IF
  137. 1390 END IF
  138. 1400 RETURN
  139. 1410  !
  140. 1420  ! This routine allows you to cut a section of a bitmap and
  141. 1430  ! save it in a file.  Note how string variables are used in
  142. 1440  ! the FILE dialog to specify the DIALOG BUTTONS attribute and
  143. 1450  ! the SELECTION attribute in order to keep the length of the
  144. 1460  ! statement compact.
  145. 1470  !
  146. 1480 Savebits: !
  147. 1490 S$="Enter file name, then click-and-drag image to save:"
  148. 1500 DIALOG "FILE",S$,Btn;SET (A1$:Btns$(*)),RETURN (A2$:Bitfile$)
  149. 1510  !
  150. 1520 SELECT Btn
  151. 1530 CASE 0
  152. 1540     S$="BMP"      ! Dump format is MS-Windows .BMP file.
  153. 1550 CASE 2
  154. 1580     RETURN
  155. 1590 END SELECT
  156. 1600  !
  157. 1610 CLEAR ERROR
  158. 1620 ON ERROR GOSUB Errtrap
  159. 1630 CONTROL @Bitmap;SET ("DUMP FORMAT":S$,"DUMP AREA":Bitfile$)
  160. 1640 OFF ERROR
  161. 1650 IF ERRN<>0 THEN
  162. 1660     DIALOG "ERROR","Can't open file."
  163. 1670 ELSE
  164. 1680     DIALOG "INFORMATION","Bitmap saved to "&S$&" file."
  165. 1690 END IF
  166. 1700  !
  167. 1710 RETURN
  168. 1720  !
  169. 1730  !
  170. 1740  ! This routine changes directories.
  171. 1750  !
  172. 1760 Chdir: !
  173. 1770 S$="Please enter the name of a directory:"
  174. 1780 DIALOG "FILE",S$,Btn;RETURN ("DIRECTORY":Dirname$)
  175. 1790 DIM Retstr$[260]
  176. 1820 Err=0
  177. 1830 CLEAR ERROR
  178. 1840 ON ERROR GOSUB Errtrap
  179. 1850 MASS STORAGE IS Dirname$
  180. 1860 OFF ERROR
  181. 1870 IF ERRN<>0 THEN
  182. 1880     DIALOG "ERROR","Can't change directory!"
  183. 1890 END IF
  184. 1900 RETURN
  185. 1910  !
  186. 1920  ! Dummy routine for trapping errors.
  187. 1930  !
  188. 1940 Errtrap: ERROR RETURN
  189. 1950  !
  190. 1960  ! ************** Go Here When Done ***********************
  191. 1970  !
  192. 1980 Finis: !
  193. 1990 ASSIGN @Main TO *
  194. 2000 CLEAR SCREEN
  195. 2010 KEY LABELS ON
  196. 2020 RUNLIGHT ON
  197. 2030 CONTROL CRT,10;Cursor
  198. 2040 END
  199.